import {NgModule} from '@angular/core';
import {NavigationEnd, NavigationError, PreloadAllModules, RouteConfigLoadStart, Router, RouterModule, Routes} from '@angular/router';
import {FormBuilder} from '@angular/forms';
import {AuthService} from './common/guard/auth.service';
import {NzMessageService} from 'ng-zorro-antd';

const routes: Routes = [];

@NgModule({
    imports: [
        RouterModule.forRoot(routes,{
            enableTracing: true, // <-- debugging purposes only
            // preloadingStrategy: PreloadAllModules  // 预加载
        })
    ],
    exports: [
        RouterModule
    ],
    declarations: []
})
// 　　imports: [], //当前模板所依赖的项，即外部模块（包括httpModule、路由等）
// 　　export:[],//声明出应用给其他的module使用
// 　　providers: [], //注入服务到当前模块
// 　　bootstrap: []//默认启动哪个组件(只有根模块才能设置bootstrap属性)
// 　　declarations: [], //属于当前模块的组件、指令及管道
export class AppRoutingModule {
    isFetching = false;
    constructor(
        private fb: FormBuilder,
        private authService: AuthService,
        private message: NzMessageService,
        private router: Router) {
        router.events.subscribe(evt => {
            if (!this.isFetching && evt instanceof RouteConfigLoadStart) {
                this.isFetching = true;
            }
            if (evt instanceof NavigationError) {
                this.isFetching = false;
                message.error(`无法加载${evt.url}路由`, {nzDuration: 1000 * 3});
                return;
            }
            if (!(evt instanceof NavigationEnd)) {
                return;
            }
            setTimeout(() => {
                this.isFetching = false;
            }, 100);
        });
    }
}
